// pages/my/my.js
import {
  getUserInfo
} from '../../api/my'
import utils from '../../utils/util'
import {
  store
} from '../../store/store'
import {
  createStoreBindings
} from 'mobx-miniprogram-bindings'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {}
  },
  goRouter(e) {
    let url = e.currentTarget.dataset.url
    utils.navigate(url, this.data.userInfo)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    this.storeBindings = createStoreBindings(this, {
      store,
      fields: ['userInfo'],
      actions: ['editUserInfo']
    })


    let that = this
    wx.getStorage({
      key: "token",
      success: async (tokenRes) => {
        await getUserInfo({
          token: tokenRes.data
        }).then(res => {
          if (res.data.code === 10000) {
            that.editUserInfo(res.data.data)
          }
        })
      }
    })
  }
})